using System;
using System.Collections.Generic;
using System.Text;
using OpenComposite.Base.Designer;
using System.Drawing;
using OpenComposite.EII.Designer.Generic;

namespace OpenComposite.EII.Designer.BusinessServices
{
	public class BusinessServiceSymbol : Symbol
	{
		#region Initialization
		public BusinessServiceSymbol()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			//this.Name = "faServiceSymbol" + GetCount(typeof(BusinessServiceSymbol));
			this.Text = "FAService";

			this.NameTextBox.BorderVisibilityStyle = BorderVisibilityStyle.MouseOverAndFocus;

			this.Size = new Size(70, 50);
			this.MinimumSize = new Size(70, 50);

			this.Border = BorderType.RoundedRectangle;
			this.BorderColor = Color.Black;
			this.BorderWidth = 2;

			this.BackColor = Color.CornflowerBlue;

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		#region Override

		#region Properties
		public override bool CanFocused
		{
			get
			{
				return true;
			}
		}
		public override bool CanMove
		{
			get
			{
				return true;
			}
		}
		public override bool CanResize
		{
			get
			{
				return true;
			}
		}
		public override bool CanSelect
		{
			get
			{
				return true;
			}
		}
		public override bool IsContainer
		{
			get
			{
				return false;
			}
		}
		public override bool NoClip
		{
			get
			{
				return false;
			}
		}
		#endregion

		#region Drag & Drop
		public override object GetDragObject(Point location, System.Windows.Forms.MouseButtons button)
		{
			return this;
		}
		public override bool IsDropAllowed(object obj, Point location, System.Windows.Forms.MouseButtons button)
		{
			return ( ( obj is BusinessServiceSymbol || obj is ExternalSymbol ) && obj != this &&
				button == System.Windows.Forms.MouseButtons.Right );
		}
		public override void DropObject(object obj, Point location, System.Windows.Forms.MouseButtons button)
		{
			if ( this.IsDropAllowed(obj, location, button) ) {
				this.DesignerViewControl.AddRoute((DesignerControl)obj, this);
			}
		}
		#endregion

		#endregion

		#region IConnector Members

		public override Point GetRouteEnd(RouteDockDirection dock, Route route)
		{
			return base.GetRouteEnd(dock, route);
		}
		public override Point GetRouteStart(RouteDockDirection dock, Route route)
		{
			return base.GetRouteStart(dock, route);
		}

		#endregion

		#region IConnectorFactory Members

		public override bool CreateRouteEnd(DesignerControl controlStart, out IConnector connector,
			out System.Drawing.Drawing2D.LineCap cap, out System.Drawing.Drawing2D.CustomLineCap customcap,
			out RouteDockDirection dockStart, out RouteDockDirection dockEnd,
			out bool useEndConnectorAsRouteEnd)
		{
			return base.CreateRouteEnd(controlStart, out connector, out cap, out customcap, out dockStart,
				out dockEnd, out useEndConnectorAsRouteEnd);
		}
		public override bool CreateRouteStart(DesignerControl controlEnd, out IConnector connector,
			out System.Drawing.Drawing2D.LineCap cap, out System.Drawing.Drawing2D.CustomLineCap customcap,
			out RouteDockDirection dockStart, out RouteDockDirection dockEnd,
			out bool useStartConnectorAsRouteStart)
		{
			bool ok = base.CreateRouteStart(controlEnd, out connector, out cap, out customcap, out dockStart,
				out dockEnd, out useStartConnectorAsRouteStart);
			if ( controlEnd is SCA.ServiceModuleSymbol ) {
				cap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
				customcap = null;
			}
			return ok;
		}

		#endregion
		#endregion
	}
}
